﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;

using AimGameLibrary.GameObject;

namespace AimGameLibrary.GameObject
{
    public class Body
    {
        public float X;
        public float Y;
        public float MyWidth;
        public float MyHight;
        public float MyForce;
        
        public Body()
        {

        }
       
        public Body(float X, float Y, float WidthW, float Hight, float Force)
        {
            this.X = X;
            this.Y = Y;
            this.MyWidth = WidthW;
            this.MyHight = Hight;
            this.MyForce = Force;
        }

        public static Body AddBody(Body body1, Body body2)
        {
            if (body1 != null && body2 != null)
                return new Body(body1.X + body2.X, body1.Y + body2.Y, body1.MyWidth + body2.MyWidth, body1.MyHight + body2.MyHight, body1.MyForce + body2.MyForce);
            else return new Body();
        }
    }

    public class GameBody : GameBaseValue
    {
        Body mybody;

        public override void LoadData(Identification getdata, int IndexData, NodeData node)
        {
            InputMode = (NodeInputMode)getdata.Items.GetValue(IndexData + 1);

            if (InputMode == NodeInputMode.Float_5)
            {
                String Temp = node.Data;
                Listnameparent.Add(Script.GetName(Temp, 5, 0));
                Listnameparent.Add(Script.GetName(Temp, 5, 1));
                Listnameparent.Add(Script.GetName(Temp, 5, 2));
                Listnameparent.Add(Script.GetName(Temp, 5, 3));
                Listnameparent.Add(Script.GetName(Temp, 5, 4));
            }
            else
            {
                Vector2 position = (Vector2)getdata.Items.GetValue(IndexData + 2);
                Vector2 size = (Vector2)getdata.Items.GetValue(IndexData + 3);
                MybodY = new Body(position.X, position.Y, size.X, size.Y, (float)getdata.Items.GetValue(IndexData + 4));
            }
        }

        public Body MybodY { get { mybody = (Body)GetParentValue(); return mybody; } set { mybody = value; SetParentValue(mybody); } }

        protected override object GetParentValue()
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Body_1
                    && Listparent[0].GetType() == typeof(GameBody))
                {
                    GameBody tempbody = (GameBody)Listparent[0];
                    return tempbody.MybodY;
                }
                else if (InputMode == NodeInputMode.Float_5
                    && Listparent.Count == 5)
                {
                    if (Listparent[0].GetType() == typeof(GameFloat) 
                        && Listparent[1].GetType() == typeof(GameFloat) 
                        && Listparent[2].GetType() == typeof(GameFloat) 
                        && Listparent[3].GetType() == typeof(GameFloat) 
                        && Listparent[4].GetType() == typeof(GameFloat))
                    {
                        GameFloat tempfloatX = (GameFloat)Listparent[0];
                        GameFloat tempfloatY = (GameFloat)Listparent[1];
                        GameFloat tempfloatWidth = (GameFloat)Listparent[2];
                        GameFloat tempfloatHight = (GameFloat)Listparent[3];
                        GameFloat tempfloatForce = (GameFloat)Listparent[4];
                        return new Body(tempfloatX.MyfloaT, tempfloatY.MyfloaT, tempfloatWidth.MyfloaT, tempfloatHight.MyfloaT, tempfloatForce.MyfloaT);
                    }
                    else return mybody;
                }
                else return mybody;
            }
            else return mybody;
        }

        protected override void SetParentValue(object obj)
        {
            if (Listparent.Count > 0)
            {
                if (InputMode == NodeInputMode.Body_1)
                {
                    if (Listparent[0].GetType() == typeof(GameBody))
                    {
                        GameBody tempbody = (GameBody)Listparent[0];
                        tempbody.MybodY = (Body)obj;
                    }
                }
                else if (InputMode == NodeInputMode.Float_5)
                {
                    if(Listparent.Count == 5)
                        if (Listparent[0].GetType() == typeof(GameFloat)
                            && Listparent[1].GetType() == typeof(GameFloat)
                            && Listparent[2].GetType() == typeof(GameFloat)
                            && Listparent[3].GetType() == typeof(GameFloat)
                            && Listparent[4].GetType() == typeof(GameFloat))
                        {
                            GameFloat tempfloatX = (GameFloat)Listparent[0];
                            GameFloat tempfloatY = (GameFloat)Listparent[1];
                            GameFloat tempfloatWidth = (GameFloat)Listparent[2];
                            GameFloat tempfloatHight = (GameFloat)Listparent[3];
                            GameFloat tempfloatForce = (GameFloat)Listparent[4];
                            Body tempobj = (Body)obj;
                            tempfloatX.MyfloaT = tempobj.X;
                            tempfloatY.MyfloaT = tempobj.Y;
                            tempfloatWidth.MyfloaT = tempobj.MyWidth;
                            tempfloatHight.MyfloaT = tempobj.MyHight;
                            tempfloatForce.MyfloaT = tempobj.MyForce;
                        }
                }
            }
        }

    }
}
